﻿using Project;
using UnityEngine;

public class Shot : BaseWeapon
{
    public int bulletNum = 3; //一次发射的子弹数量
    public float bulletAngle = 15; //子弹之间的角度
    public GameObject bulletPrefab; //子弹预制体
    public Transform firePos;

    public override string Name => "Shot";

    protected override void Attack()
    {
        int median = bulletNum / 2;
        for (int i = 0; i < bulletNum; i++)
        {
            GameObject go = Instantiate(bulletPrefab, firePos.position, firePos.rotation);
            if (bulletNum % 2 == 1)
            {
                Vector3 bulletDir  = Quaternion.AngleAxis(bulletAngle * (i - median), Vector3.forward) * dir;
                go.GetComponent<BaseBullet>().OnFire(bulletDir);
            }
            else
            {
                Vector3 bulletDir = Quaternion.AngleAxis(bulletAngle * (i - median) + bulletAngle / 2, Vector3.forward) * dir;
                go.GetComponent<BaseBullet>().OnFire(bulletDir);
            }
            
        }
    }
}
